import os
import multiprocessing


class SubProcess(multiprocessing.Process):
    def __init__(self, name):
        multiprocessing.Process.__init__(self)
        self.name = name

    def run(self):
        print('子进程%s(%s)启动' % (self.name, os.getpid()), '父进程pid=', os.getppid())


if __name__ == '__main__':
    print('父进程%s启动' % os.getpid())

    for i in range(3):
        p = SubProcess(f'子进程{i}')
        p.start()
        p.join()

    print('父进程%s结束' % os.getpid())